//
//  DesignCell.swift
//  SpinCut
//
//  Created by dai simon on 2024/7/6.
//

import UIKit

class DesignCell: UICollectionViewCell {
    lazy var bgView: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor(hex: "#FFFFFF", alpha: 0.02)
        view.layer.cornerRadius = 20
        view.layer.borderWidth = 1
        view.layer.borderColor = UIColor(hex: "#FFFFFF", alpha: 0.1).cgColor
        view.clipsToBounds = true
        return view
    }()
    
    lazy var imgView: UIImageView = {
       let view = UIImageView()
        view.backgroundColor = .black
        view.clipsToBounds = true
        view.layer.cornerRadius = 66
        
        view.layer.borderWidth = 1
        view.layer.borderColor = UIColor(hex: "#FFFFFF", alpha: 0.1).cgColor
        return view
    }()
    
    lazy var shareBtn: UIButton = {
       let view = UIButton()
        view.setBackgroundImage(UIImage(named: "icon_share"), for: .normal)
        return view
    }()

    lazy var titleLabel: UILabel = {
        let view = UILabel()
        view.font = UIFont.systemFont(ofSize: 13)
        view.textColor = .white
        view.textAlignment = .center
        return view
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        contentView.addSubview(titleLabel)
        self.titleLabel.snp.makeConstraints { make in
            make.left.right.equalToSuperview().inset(25)
            make.bottom.equalToSuperview()
        }
        
        self.contentView.addSubview(bgView)
        bgView.snp.makeConstraints { make in
            make.left.right.equalToSuperview().inset(25)
            make.top.equalTo(25)
            make.bottom.equalTo(self.titleLabel.snp.top).offset(-18)
        }
        
        bgView.addSubview(self.imgView)
        self.imgView.snp.makeConstraints { make in
            make.edges.equalToSuperview().inset(16)
        }
        
        bgView.addSubview(shareBtn)
        shareBtn.snp.makeConstraints { make in
            make.width.height.equalTo(16)
            make.right.bottom.equalToSuperview().offset(-16)
        }

        let cellWidth: CGFloat = (ScreenWidth - 36 * 4) / 5.0 - 32 - 50
        imgView.layer.cornerRadius = cellWidth / 2
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setup(_ title: String) {
        titleLabel.text = title
    }

    override func prepareForReuse() {
        super.prepareForReuse()
       
        imgView.image = nil
        titleLabel.text = nil
    }
    
}
